home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
magic.zip
/
MAGIC.DOC
next >
Wrap
Text File
|
1987-08-23
|
11KB
|
265 lines
magic magic magic DNS C Documentation Page -1-
NAME NAME NAME
magic special-characters-to-output
magic -get arguments
magic -detab[n] [infile [outfile]]
DESCRIPTION DESCRIPTION DESCRIPTION
magic magic magic is a multipurpose utility for the IBM PC & compatibles. It
allows you to easily output "special" character stings to the
screen (like escape sequences), provides interactive batch file
input, and can detab (expand tabs into whitespace) in a text
file.
__________ _______ __________ Outputting Special Characters
magic magic Program magic can be used to generate character sequences which
magic magic are normally hard to generate. Typing magic alone shows how to
use the program. The following special symbols are recognized by
magic magic magic. The curly braces are required.
{ESC} Writes the ESC character
{CR} Writes a CRLF (Enter)
{TAB} Writes a TAB
{FF} Writes a form feed
{0xnn} Writes hex number nn
^S Writes Ctrl-S
___ Note that any character can be written with the {0xnn} mechanism,
and that a ^ (hat) immediately preceding a character writes the
control of that character.
Our AUTOEXEC.BAT's have the following lines of code in them:
magic {cr} | print /B:4096 > null
magic {ff} > lpt1
magic {esc}[2J{esc}[34;46m
magic magic The first example installs the DOS PRINT command, where magic is
used to write an Enter, which is piped into PRINT to answer the
question PRINT asks you.
The second example sends a form feed to our printer, ensuring it
is starting out on a fresh, unbent page.
The third example shows how we can write some ESC sequences to
the screen to clear the screen and set our screen colors.
_ _____ ____ ________ A Batch File Enhancer
magic magic magic can be invoked to get responses from the user, and set
error return codes to indicate how the user responded. Usage is
as follows:
magic -get arguments
magic magic August 23, 1987 magic
magic magic magic DNS C Documentation Page -2-
Arguments are as follows:
-beep
-prompt "Query for user"
-default=response
-timeout=nn
resp=errnum
-beep magic -beep magic The -beep option beeps the user when magic is run, to encourage
the user to look at his screen.
-default -df -default -df The -default option (-df for short) allows you to specify what
the default response should be (if the user just hits Enter).
-timeout -to -timeout -to The -timeout option (-to for short) allows you to specify a
number of seconds after which the default answer will be supplied
____ automatically. You must supply a default if you expect the
timeout to work.
resp errnum resp errnum resp is text which the user is expected to respond with. errnum
is a number, 0-255, which will be returned as an error code. The
error code can be checked in a batch file easily.
Here is a real example of usage:
magic -get abc=1 def=2 ghi=3
will return an error of 1 if the user types in abc, a 2 if he
types in def, etc. When typing in the relationship between a
string and an error code, there can be no spaces.
Here are some more complicated examples:
magic -get -prompt "Format (y/n)? " -default=y y=1 n=2
magic -get -default=abc -timeout=20 abc=1 def=2 ghi=3
magic magic In the first example, magic detects that all possible responses
are a single character, and will not require the user to hit
Enter (i.e. just hitting Y or N is enough).
-prompt -pr -prompt -pr If you use the -prompt option (-pr for short), the next thing
following the -prompt is taken to be the prompt to display.
Surrounding the prompt string with quotes (as shown above) allows
you to have a multi word prompt.
magic magic Here is a BAT file which shows how magic is used in real life:
magic magic August 23, 1987 magic
magic magic magic DNS C Documentation Page -3-
echo off
echo Enter either abc, def, or ghi
magic -get -default=abc abc=1 def=2 ghi=3
rem = Errorlevel checks in reverse numeric order =
if errorlevel 3 goto three
if errorlevel 2 goto two
if errorlevel 1 goto one
goto quit
rem Action if user types abc
:one
echo one
goto quit
rem Action if user types def
:two
echo two
goto quit
rem Action if user types ghi
:three
echo three
goto quit
:quit
Note that the error level checks are in decreasing numeric order.
This is required due to the nature of the way DOS performs the
tests.
____ ________ File Detabber
magic magic You can use magic to remove (expand) tabs from a file. The
default tab expansion is 4 spaces. This default can be overridden
by setting an environment variable called TAB to your desired tab
expansion. You can also tack a number on to the end of the -detab
option on the command line, e.g.
magic -detab3
The number following the -detab overrides both the program
___ default and your (optional) TAB environment variable.
With no other command line arguments, input is expected to come
from standard input, and the detabbed output will go to the
magic